package com.zzh.demo.core.common.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * description： <br>
 * createTime: 2018/1/811:21 <br>
 *
 * @author zzh
 */
public class CookieUtils {

    /**
     *
     * Method Name：getCookieValue
     * Method Description: 从请求中获取指定名称的Cookie的值<br>
     *
     * @param   request     请求对象
     * @param   cookieName  cookie名称
     * @return  获取到的结果，没有返回null
     * <p>creator：zzh
     * <p>createTime：2018/1/8 11:31
     */
    public static String getCookieValue(HttpServletRequest request, String cookieName) {
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : request.getCookies()) {
                if (cookie.getName().equalsIgnoreCase(cookieName)) {
                    return cookie.getValue();
                }
            }
        }
        return null;
    }
}
